import { BasicColumn } from '@/components/Table';
import { FormSchema } from '@/components/Table';
import { h } from 'vue';
import { Tag } from 'ant-design-vue';
import { cacheApi } from '@/api/sys/common';
import { useI18n } from '@/hooks/web/useI18n';

const { t } = useI18n();
export const columns: BasicColumn[] = [
  {
    title: t('标题'),
    align: 'center',
    dataIndex: 'title',
  },
  {
    title: t('摘要'),
    align: 'center',
    dataIndex: 'msgAbstract',
  },
  {
    title: t('开始时间'),
    align: 'center',
    dataIndex: 'startTime',
  },
  {
    title: t('结束时间'),
    align: 'center',
    dataIndex: 'endTime',
  },
  {
    title: t('发布人'),
    align: 'center',
    dataIndex: 'sender',
  },
  {
    title: t('优先级'),
    align: 'center',
    dataIndex: 'priorityStr',
  },
  {
    title: t('消息类型'),
    align: 'center',
    dataIndex: 'msgCategoryStr',
  },
  {
    title: t('通告对象'),
    align: 'center',
    dataIndex: 'msgTypeStr',
  },

  {
    title: t('发布状态'),
    align: 'center',
    dataIndex: 'sendStatusStr',
    customRender: ({ text, record }) => {
      let color = 'default';
      if (record.sendStatus == 1) {
        color = 'success';
      }
      if (record.sendStatus == 2) {
        color = 'error';
      }
      return h(Tag, { color }, text);
    },
  },
  {
    title: t('发布时间'),
    align: 'center',
    dataIndex: 'sendTime',
  },
  {
    title: t('撤销时间'),
    align: 'center',
    dataIndex: 'cancelTime',
  },

  {
    title: t('创建时间'),
    align: 'center',
    dataIndex: 'createTime',
  },
  {
    title: t('修改用户'),
    align: 'center',
    dataIndex: 'updateUser',
  },
  {
    title: t('创建用户'),
    align: 'center',
    dataIndex: 'createUser',
  },
  {
    title: t('修改时间'),
    align: 'center',
    dataIndex: 'updateTime',
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'titile',
    label: t('标题'),
    component: 'Input',
    colProps: { span: 8 },
    required: false,
  },
  {
    field: 'msgCategory',
    label: t('消息类型'),
    component: 'ApiSelect',
    componentProps: {
      api: cacheApi,
      params: { keyCode: 'notice_type' },
    },
    colProps: { span: 8 },
  },
];
export const formSchema: FormSchema[] = [
  {
    field: 'id',
    label: '',
    component: 'Input',
    show: false,
  },
  {
    field: 'titile',
    label: t('标题'),
    component: 'Input',
    required: true,
    colProps: {
      span: 12,
    },
  },
  {
    field: 'msgAbstract',
    label: t('摘要'),
    component: 'InputTextArea',
    required: true,
    colProps: {
      span: 24,
    },
  },

  {
    field: 'timeRange',
    label: t('生效起止时间'),
    component: 'RangePicker',
    colProps: {
      span: 24,
    },
    componentProps: {
      format: 'YYYY-MM-DD HH:mm:ss',
      valueFormat: 'YYYY-MM-DD HH:mm:ss',
      placeholder: [t('开始时间'), t('结束时间')],
      showTime: { format: 'HH:mm:ss' },
    },
  },
  {
    field: 'priority',
    label: t('优先级'),
    required: true,
    component: 'ApiRadioGroup',
    defaultValue: 'general',
    componentProps: {
      dictCode: 'notice_level',
    },
    colProps: {
      span: 24,
    },
  },
  {
    field: 'msgCategory',
    label: t('消息类型'),
    component: 'ApiRadioGroup',
    defaultValue: 'tz',
    componentProps: {
      dictCode: 'notice_type',
    },
    required: true,
    colProps: {
      span: 24,
    },
  },
  {
    field: 'msgType',
    label: t('通告对象类型'),
    component: 'ApiRadioGroup',
    required: true,
    defaultValue: 'toAll',
    componentProps: {
      dictCode: 'notice_modify_type',
    },
    colProps: {
      span: 24,
    },
  },
  {
    field: 'userIds',
    label: t('指定用户'),
    component: 'ApiSelect',
    required: true,
    ifShow: ({ values }) => values.msgType === 'toUser',
    colProps: {
      span: 24,
    },
    componentProps: {
      mode: 'multiple',
      api: cacheApi,
      params: { keyCode: 'user' },
    },
  },
  {
    field: 'msgContent',
    label: t('内容'),
    component: 'RichText',
    required: true,
    colProps: {
      span: 24,
    },
  },
];
